#include"../include/threadPool.h"
#include"../include/worker.h"
int threadPoolInit(threadPool_t *pthreadPool,int workerNum){
    tidArrInit(&pthreadPool->tidArr,workerNum);
    taskQueueInit(&pthreadPool->taskQueue);
    pthread_mutex_init(&pthreadPool->mutex,NULL);
    pthread_cond_init(&pthreadPool->cond,NULL);
    return 0;
}
//创建子线程
int makeWorker(threadPool_t*pthreadPool){
    for(int i = 0;i<pthreadPool->tidArr.workerNum;i++){
        pthread_create(&pthreadPool->tidArr.arr[i],NULL,threadFunc,pthreadPool);
    }
    return 0;
}

int tcpInit(char *ip,char *port){
    int sockfd = socket(AF_INET,SOCK_STREAM,0);
    int flag = 1;
    setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&flag,sizeof(flag));
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr(ip);
    addr.sin_port = htons(atoi(port));

    bind(sockfd,(struct sockaddr*)&addr,sizeof(addr));

    listen(sockfd,1024);
    return sockfd;
}
int epollAdd(int epfd,int fd){
    struct epoll_event events;
    events.events = EPOLLIN;
    events.data.fd = fd;
    epoll_ctl(epfd,EPOLL_CTL_ADD,fd,&events);
    return 0;
}
int epollDel(int epfd,int fd){
    epoll_ctl(epfd,EPOLL_CTL_DEL,fd,NULL);
    return 0;
}
